/***************************************************************************
 *   Copyright (C) 2009 by Zheng Yonglei
 *   zhengyonglei@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef RECITEWORDSWIDGET_H
#define RECITEWORDSWIDGET_H

#include <QtGui/QWidget>
#include <QtGui/QDialog>
#include <QWidget>
#include <QString>
#include <QPushButton>
#include <QTextBrowser>
#include <QSound>
#include <QMessageBox>
#include <QFont>
#include <QTextStream>
#include <QFile>
#include <QProcess>
#include <QShortcut>
#include <QPalette>
#include <QGridLayout>

#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#include "ui_ReciteWordsWidget.h"
#include "WordManager.h"
#include "Logger.h"
#include "Options.h"
#include "ReciteTest_YesNo.h"
#include "ReciteTest_MultiChoice.h"
#include "ReciteTest_Spell.h"
#include "MessageBox.h"
#include "EndReciteTaskDialog.h"
//#include "config.h"

using namespace std;

class ReciteWordsWidget : public QWidget
{
    Q_OBJECT

private:
    Ui::ReciteWordsWidgetClass ui;

	QShortcut* mDiffLev1;
	QShortcut* mDiffLev2;
	QShortcut* mDiffLev3;
	QShortcut* mDiffLev4;
	QShortcut* mDiffLev5;
	QShortcut* mDiffLev6;

	QGridLayout* dynamicButtonGrid;
	ReciteTest_YesNo* mReciteTest_YesNo;
	ReciteTest_MultiChoice* mReciteTest_MultiChoice;
	ReciteTest_Spell* mReciteTest_Spell;
	vector<ReciteTestMethodBase*>testMethod;

	map<TestMethod, QString> mTestProBarStyleSheets;

	EndReciteTaskDialog* mEndReciteTaskDialog;

	bool mAutoSpeak;

public:
    ReciteWordsWidget(QWidget *parent = 0);
    ~ReciteWordsWidget();

    void initReciteTask();

    void beginNewReciteTest();
    bool endCurReciteTask();

    void updateImportanceLevel();
    void clearDisplay(){ui.reciteDisplayArea->getTextBrowser()->clear();}

    QTextBrowser* reciteDiaplay(){return ui.reciteDisplayArea->getTextBrowser();}
    WordBrowser* getWordBrowser(){return ui.reciteDisplayArea;}

public slots:
	void setImpLev1(){setWordImpLev(0);}
	void setImpLev2(){setWordImpLev(1);}
	void setImpLev3(){setWordImpLev(2);}
	void setImpLev4(){setWordImpLev(3);}
	void setImpLev5(){setWordImpLev(4);}
	void setImpLev6(){setWordImpLev(5);}
	void setWordImpLev(int levelArg);

	void updateMemoryLevel();
	void memoryLevelChangedTo(int value){ui.memoryLevelBar->setValue(value);}
	void totalReciteCountChangedTo(int value){ui.reciteCountLCD->display(value);}
	void totalFinishedCountChangedTo(int value){ui.reciteProgressBar->setValue(value);}

	void reciteNextWord();
	void testError_NoWord();

	void speakButtonClicked();

signals:
	void updateMainBulletin();

	void finishCurTask();
	void openSelectListDialog();
	void openAnalysisDialog();
};

#endif // RECITEWORDSWIDGET_H
